package com.net.SortEmp;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;


class Employee implements Comparable<Employee>
{
	int id;
    String name;
    Date dob;
    
    public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getDob() {
		return dob;
	}

	public void setDob(Date dob) {
		this.dob = dob;
	}

	Employee(int id, String name, Date dob)
    {
    	this.id = id;
    	this.name = name;
    	this.dob = dob;
    }

	

	@Override
	public int compareTo(Employee o) {
		
		int result = this.name.compareTo(o.name);
		
		if(result == 0)
		{
			result = (this.id>o.id ?1 : this.id<o.id?-1:0);
		}
		
		return result;
	}
	
}




public class EmployeeTest {

	public static void main(String[] args) throws Exception
	{
      DateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy");
      Employee emp1 = new Employee(6, "dinesh", dateFormat.parse("22-11-2014"));
      Employee emp2 = new Employee(10, "dinesh", dateFormat.parse("22-11-2014"));
      Employee emp3 = new Employee(1, "dinesh", dateFormat.parse("22-11-2014"));
      Employee emp4 = new Employee(3, "yuvraj", dateFormat.parse("22-11-2015"));
      Employee emp5 = new Employee(10, "any", dateFormat.parse("22-11-2013"));

      List<Employee> list = new ArrayList();
      list.add(emp1);
      list.add(emp2);
      list.add(emp3);
      list.add(emp4);
      list.add(emp5);
      
     Collections.sort(list);
     
     Iterator<Employee> it = list.iterator();
     
     while(it.hasNext())
     {
    	 Employee e = it.next();
    	 
    	 System.out.println(e.getId() + "   " + e.getName() + "  " +e.getDob());
     }
    
     
    }

}
